import request from "@/utils/request";
import { Profile, SourceEnum } from "@/types/user";
import { ApiRes } from "@/types/data";

/**
 * 用户名密码登录
 * @param account  用户名
 * @param password  密码
 */
export function postLoginAPI (account: string, password: string) {
  return request<ApiRes<Profile>>({
    url: '/login',
    method: "post",
    data: {
      account,
      password
    }
  });
}



/**
 * 发送验证码
 * @param mobile  手机号
 */
export function getLoginCodeAPI (mobile: string) {
  return request<ApiRes<null>>({
    url: '/login/code',
    method: "get",
    params: {
      mobile
    }
  });
}


/**
 * 手机号登录
 * @param mobile  手机号
 * @param code  验证码
 */
export function postLoginCodeAPI (data: { mobile: string, code: string }) {
  return request<ApiRes<Profile>>({
    url: '/login/code',
    method: "post",
    data
  });
}


/**
 * qq登录
 * @param unionId  第三方登录返回的 openId
 * @param source   source: 1为pc，2为webapp，3为微信小程序, 4为Android, 5为ios, 6为qq, 7为微信
 */

export function QQLoginAPI (data: { unionId: string, source: SourceEnum }) {
  return request<ApiRes<Profile>>({
    url: '/login/social',
    method: "post",
    data
  });
}


/**
 *  绑定qq的短信验证码
 * @param mobile  手机号
 */

export function sendQQBindAPI (mobile: string) {
  return request({
    url: '/login/social/code',
    method: "get",
    params: {
      mobile
    }
  });
}

/**
 *  绑定qq的短信验证码
 * @param openId  第三方登录返回的 openId
 * @param mobile  手机号
 * @param code    验证码
 */

export function qqBindLoginAPI (openId: string, mobile: string, code: string) {
  return request<ApiRes<Profile>>({
    url: '/login/social/bind',
    method: "post",
    data: {
      openId,
      mobile,
      code
    }
  });
}




/**
 *  获取短信验证码
 *  绑定qq的短信验证码
 * @param mobile  手机号
 */
export function sendQQPathMsgAPI (mobile: string) {
  return request<ApiRes<Profile>>({
    url: '/register/code',
    method: "get",
    params: {
      mobile,
    }
  });
}


/**
 * 新建完善资料
 * @param data  
 */

export function qqPatchLoginAPI (data: any) {
  return request<ApiRes<Profile>>({
    url: `/login/social/${data.openId}/complement`,
    method: "post",
    data
  });
}

